Article originally written for BATPUG Journal
Written with BRIEF text editor.



                   DUAL MONITORS by Brian Whitnall


This article describes how a second monitor can be physically fitted
to a PC compatible computer, how dual monitors aid debugging with the
Turbo Debugger, and how to write applications accessing dual
monitors.


                         PHYSICAL ARRANGEMENT


The IBM architecture supports two simultaneous monitors. Video cards
have two or three physical attributes : the RAM address in memory
space, port addresses in I/O space, and optionally ROM BIOS address
in memory space. There are three different types of video card, each
with it own attributes.


MDA - monochrome display adaptor, also Hercules Graphics
        RAM     B0000-B7FFF
        I/O     3Bx
        BIOS    none


CGA - colour graphics adaptor
        RAM     B8000-BFFFF
        I/O     3Dx
        BIOS    none


EGA/VGA - enhanced graphics adaptor/video graphics array
        RAM     MDA or CGA or A0000-AFFFF
        I/O     3Cx and (3Bx or 3Dx)
        BIOS    C0000-C7FFF


Video cards may be mixed so long as there is no memory or I/O
contention. Hence the following combinations are legal:
        MDA + CGA
        MDA + EGA/VGA in colour mode
        CGA + EGA/VGA in monochrome mode (MDA emulation)
However it is not possible it mix two EGA/VGA cards, one colour and
one monochrome due to contention of the 3Cx ports.


Two cards are fully supported by BIOS, and one may switch between
cards using DOS commands MODE MONO and MODE CO80. With two identical
EGA cards it is possible to fit two of them, both in colour text
mode, by changing the port address of the second from 3xx to 2xx by a
link on the card. There is no BIOS support for the 2xx card, and so it
is the users responsibility to initialise all registers, and set the
RAM address to A0000-A7FFF. With such a set-up one may have three
monitors: 2 EGA, 1 MDA.


Assuming you already have some sort of colour display (CGA/EGA/VGA),
then an MDA card plus monitor is required. MDA cards are now very
cheap, a new one costing from 13+VAT, or a second hand one for half
that price. Good sources for new and second-hand items are Computer
Shopper and Micro Computer Mart magazines. Check second-hand monitors
for screen-burn or lack of intensity. If your mono card has a printer
port, this will become LPT1, and your original port will be LPT2. The
ports can be swapped by exchanging words in ram at 40:08 and 40:0A.


                              DEBUGGING


All stand-alone Turbo Debuggers support dual monitor operation. This
is a very powerful aid when debugging, especially for graphics
programs since it enables the primary colour monitor to display the
programs normal output, with the second monochrome monitor
displaying the source code.


Whilst it is possible to debug graphics mode programs with a single
colour monitor, this involves copious video mode changes. When
changing back to graphics, the top section of the screen often
becomes corrupt where the text mode font has been stored on the second
plane, and any colour palette changes will be lost.


To debug a Pascal or assembler application, start the debugger from
your colour screen using the command TD -DO programname. This will
cause the program's normal output to be sent to the colour monitor,
and the debuggers windows to be sent to the monochrome monitor. The
current line is shown in inverse video, and breakpoints are shown
underlined. On exit, the debugger returns to the colour screen.


                        INTEGRATED ENVIRONMENT


Borland Integrated Development Environments from version 5 on can
also operate in dual monitor mode. When invoking the IDE add the
option switch /D, e.g. TURBO /D. As with the debugger, the IDE will
appear on the alternate screen, leaving the primary screen for
program output. With version 6, in Options, Environment, Startup one
can select Dual monitor support instead of the command line switch.


                       APPLICATION PROGRAMMING


A second monitor may be useful in an application either as a
temporary output for internally generated debugging information or as
a second screen continuously displaying vital status information
whilst the user selects different interactive screen on the primary
monitor.


A simple way to access more than one screen is to provide an enhanced
fast string write procedure which directly accesses video ram. Such a
procedure may be in Pascal or Assembler. Typically such procedures
are passed the string, attribute and X and Y coordinate parameters,
and automatically choose the appropriate video segment (B000 or
B800). An enhanced procedure would select the video segment against
an additional parameter.


PROGRAM FastWriteDemo;
CONST
  Screen_Width: INTEGER = 80;
TYPE
  VideoSeg = (MonoSeg,ColourSeg);

PROCEDURE DirectWrite(S: String; Attr,X,Y: BYTE; Screen: VideoSeg);
VAR
  I: INTEGER;
  VidSeg,VidOfs: WORD;
BEGIN
  IF Screen = MonoSeg THEN
    VidSeg := $B000
  ELSE
    VidSeg := $B800;
  VidOfs := ((Y * Screen_Width) + X) SHL 1;
  FOR I:=1 TO Length(S) DO BEGIN
    Mem[VidSeg:VidOfs]:=BYTE(S[I]);
    INC(VidOfs);
    Mem[VidSeg:VidOfs]:=Attr;
    INC(VidOfs);
  END;
END;  { DirectWrite }

BEGIN
  DirectWrite('Hello colour screen',$1E,30,12,ColourSeg);
  DirectWrite('Hello mono screen',$07,30,12,MonoSeg);
END.

